package thread;

import java.io.File;
import java.io.FileFilter;
import java.util.concurrent.BlockingDeque;

public class FileCrawler implements Runnable {
	private final BlockingDeque<File>fileQueue;
	private final FileFilter fileFilter;
	private final File root;
	
	public FileCrawler(BlockingDeque<File>fileQueue,FileFilter fileFilter,File root) {
		this.fileQueue=fileQueue;
		this.fileFilter=fileFilter;
		this.root=root;
	}
	@Override
	public void run() {
		try{
			crawal(root);
		}catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	private void crawal(File root2) throws InterruptedException{
		File[]entries=root2.listFiles(fileFilter);
		if(entries!=null){
			for(File entry:entries){
				if(entry.isDirectory()){
					crawal(entry);
				}else if(!alreadyIndexed(entry)){
					fileQueue.put(entry);
				}
			}
		}
	}
	private boolean alreadyIndexed(File entry) {
		return false;
	}

}
